﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CSharp.Libs.Koc;

namespace CSharp.Libs.WPF.UserControls
{
    /// <summary>
    /// Interaktionslogik für UserControl1.xaml
    /// </summary>
    public partial class KocMarchControl : UserControl
    {
        #region declarations
        private KocMarchControlViewModel _KMCVM = null;
        private Kernel _KRNL = null;
        private KocKernel2ViewModel _KK2VM = null;
        #endregion



        #region constructor / finalizer
        public KocMarchControl()
        {
            InitializeComponent();
        }
        #endregion



        #region private functions
        private void _InitializeVM(
            Kernel KRNL,
            KocKernel2ViewModel KK2VM)
        {
            _KRNL = KRNL;
            _KK2VM = KK2VM;
            _KMCVM = new KocMarchControlViewModel(this.Dispatcher, _KRNL, _KK2VM);
            DataContext = _KMCVM;

            _KK2VM.AfterServerChange += new KocKernel2ViewModel.AfterServerChangeEventHandler(_KK2VM_AfterServerChange);
            _KK2VM.AfterUserChange += new KocKernel2ViewModel.AfterUserChangeEventHandler(_KK2VM_AfterUserChange);

            //kocCitySelector1.Initialize(_KRNL);
            //kocCitySelector1.ViewModel.ServerNr = _KK2VM.ServerId;
            //if (_KK2VM.SelectedUser != null) { kocCitySelector1.ViewModel.UserFbUid = _KK2VM.SelectedUser.FbUid; }

            //kocKnightSelector1.Initialize(_KRNL);
            //kocKnightSelector1.ViewModel.ServerNr = _KK2VM.ServerId;
            //if (_KK2VM.SelectedUser != null) { kocKnightSelector1.ViewModel.UserFbUid = _KK2VM.SelectedUser.FbUid; }

            //Set example march values
            MarchHandlerItem mhi= new MarchHandlerItem();
            mhi.MarchType = MarchTypes.Attack;
            mhi.CityID = 123456;
            mhi.XCoord = 12;
            mhi.YCoord = 12;
            mhi.KnightID = 987654;
            mhi.U2 = 1;
            _KMCVM.SetMarchHandlerItem(mhi);
        }

        void _KK2VM_AfterUserChange(object sender, UserChangeEventArgs ucea)
        {
            //kocCitySelector1.ViewModel.UserFbUid = ucea.NewUser.FbUid;
            //kocKnightSelector1.ViewModel.UserFbUid = ucea.NewUser.FbUid;
        }

        void _KK2VM_AfterServerChange(object sender, ServerChangeEventArgs scea)
        {
            //kocCitySelector1.ViewModel.ServerNr = scea.NewServerId;
            //kocKnightSelector1.ViewModel.ServerNr = scea.NewServerId;
        }
        #endregion



        #region interface
        #region properties
        /// <summary>
        /// 
        /// </summary>
        /// <history>created  12.06.2012</history>
        public KocMarchControlViewModel KMCVM { get { return _KMCVM; } }

        /// <summary>
        /// 
        /// </summary>
        /// <history>created  10.07.2012</history>
        public KocMarchControlViewModel ViewModel { get { return _KMCVM; } }
        #endregion

        #region methods
        public void InitializeVM(
            Kernel KRNL,
            KocKernel2ViewModel KK2VM)
        {
            _InitializeVM(KRNL,KK2VM);
        }
        #endregion

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            _KMCVM.MHI.Gold = 3333333;
            _KMCVM.MHI.MarchType = MarchTypes.Scout;
        }
        #endregion
    }
}
